<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>添加用户</title>
    <link rel="shortcut icon" href="https://www.baidu.com/favicon.ico" type="image/x-icon">
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}">
</head>
<body >
<div style="display: flex;justify-content: center;align-items: center;margin-top: 10%">
    <form class="layui-form" action="">
        <input type="hidden" name="userId">
        <input type="hidden" name="userPassword" value="123456">
        <input type="hidden" name="userImg" value="defaul.jpg">
        <div class="layui-form-item">
            <label class="layui-form-label">用户名</label>
            <div class="layui-input-inline">
                <input type="text" name="userName" required lay-verify="required" placeholder="用户名"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">用户地址</label>
            <div class="layui-input-inline">
                <input type="text" name="address" required lay-verify="required" placeholder="请输入用户地址"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">联系方式</label>
            <div class="layui-input-inline">
                <input type="text" name="userPhone" required lay-verify="required" placeholder="请输入联系方式"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="formDemo">添加</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
<script th:src="@{/layui/layui.js}"></script>
<script th:inline="javascript">
    //Demo
    layui.use('form', function () {
        var form = layui.form;
        var $ = layui.$;
        //提交
        form.on('submit(formDemo)', function (data) {
            $.ajax({
                url: "http://localhost:8080/user/addUser",
                data: data.field,
                success: function (res) {
                    if (res) {
                        layer.msg('添加成功', {
                            icon: 1,
                            time: 1500
                        });
                        setTimeout('parent.location.reload()', 1500)
                    } else {
                        layer.msg('添加失败', {
                            icon: 2,
                            time: 1500
                        });
                        setTimeout('parent.location.reload()', 1500)
                    }
                }
            })
            return false;
        });
    });
</script>
</body>
</html>